package com.shaoshaohuo.app.view;

import com.shaoshaohuo.app.R;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;

/**
 * 进度条
 * @author YinSF
 * @createDate 2015-11-15
 */
public class ProgressDialog {
	private Dialog mDialog;
	private Handler handler;
	private Runnable runnable;
	private Context context;

	public ProgressDialog(Context context) {
		this.context = context;
	}
	

	public void startLoadingDialog() {
    	if (handler == null) {
    		handler = new Handler();
    	}
    	if (runnable == null) {
    		runnable = new Runnable() {
    			
    			@Override
    			public void run() {
    				if (mDialog == null) {
    					mDialog = new Dialog(context, R.style.dialog);
    					View contentView = LayoutInflater.from(context).inflate(R.layout.layout_loadingdialog, null);
    					mDialog.setContentView(contentView);
    					Window window = mDialog.getWindow();
    					window.setWindowAnimations(R.style.customDialog_anim_style);
    					mDialog.setCanceledOnTouchOutside(false);
    					mDialog.setCancelable(true);
    				}
    				
    				mDialog.show();
    			}
    		};
    	}
    	handler.postDelayed(runnable, 200);
    }

    public void dismissLoadingDialog() {
        if (handler != null && runnable != null) {
        	handler.removeCallbacks(runnable);
        	handler = null;
        	runnable = null;
        	if (mDialog != null) {
        		mDialog.dismiss();
        	}
        }
    }
}